/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2024-12-22 14:10:14
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-02-18 23:05:20
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/repository/LearnRecordRepository.java
 */
package com.angus.modules.content.repository;

import com.angus.modules.content.domain.LearnRecord;
import com.angus.modules.content.mapper.LearnRecordMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author liyanan
 * @date 2024/11/27 3:54 PM
 * @description
 */
@Repository
public class LearnRecordRepository extends ServiceImpl<LearnRecordMapper, LearnRecord> {
    public void addLearnRecord(Long userId, String courseCode, Integer unitNum, Long groupId,String groupFlag) {

        LearnRecord learnRecord = new LearnRecord();
        learnRecord.setCourseCode(courseCode);
        learnRecord.setUnitNum(unitNum);
        learnRecord.setGroupId(groupId);
        learnRecord.setGroupFlag(groupFlag);
        learnRecord.setUserId(userId);
        learnRecord.setCreateTime(LocalDateTime.now());
        baseMapper.insert(learnRecord);
    }

    public List<LearnRecord> getLearnRecord(Long userId, String courseCode,Integer unitNum) {
       return baseMapper.selectList(Wrappers.lambdaQuery(LearnRecord.class)
                .eq(LearnRecord::getUserId, userId)
                .eq(LearnRecord::getCourseCode, courseCode)
                .eq(LearnRecord::getUnitNum, unitNum)
                .eq(LearnRecord::getDelFlag, 0)
                .orderByDesc(LearnRecord::getCreateTime)
        );
    }
}
